001 /*
002 * Copyright 2005 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.lang;
020
021 /**
022 * Classoader category enumeration.
023 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
024 * @version 1.0.1
025 */
026 public final class Category extends ValuedEnum
027 {
028 static final long serialVersionUID = 1L;
029
030 /**
031 * Undefined category.
032 */
033 public static final Category UNDEFINED = new Category( "undefined", -1 );
034
035 /**
036 * System category.
037 */
038 public static final Category SYSTEM = new Category( "system", 0 );
039
040 /**
041 * API category.
042 */
043 public static final Category PUBLIC = new Category( "public", 1 );
044
045 /**
046 * SPI category.
047 */
048 public static final Category PROTECTED = new Category( "protected", 2 );
049
050 /**
051 * Implementation category.
052 */
053 public static final Category PRIVATE = new Category( "private", 3 );
054
055 /**
056 * Array of scope enumeration values.
057 */
058 private static final Category[] ENUM_VALUES =
059 new Category[]
060 {
061 SYSTEM,
062 PUBLIC,
063 PROTECTED,
064 PRIVATE,
065 UNDEFINED
066 };
067
068 /**
069 * Returns an array of activation enum values.
070 * @return the activation policies array
071 */
072 public static Category[] values()
073 {
074 return ENUM_VALUES;
075 }
076
077 /**
078 * Internal constructor.
079 * @param label the enumeration label.
080 * @param index the enumeration index.
081 */
082 private Category( String label, int index )
083 {
084 super( label, index );
085 }
086
087 /**
088 * Return a string representation of the category.
089 * @return the category name in uppercase
090 */
091 public String toString()
092 {
093 return getName().toUpperCase();
094 }
095
096 /**
097 * Create a category by parsing the supplied value.
098 * @param value the category name
099 * @return the corresponding category
100 * @exception IllegalArgumentException if the value is not recognized
101 */
102 public static Category parse( int value ) throws IllegalArgumentException
103 {
104 if( SYSTEM.getValue() == value )
105 {
106 return SYSTEM;
107 }
108 else if( PUBLIC.getValue() == value )
109 {
110 return PUBLIC;
111 }
112 else if( PROTECTED.getValue() == value )
113 {
114 return PROTECTED;
115 }
116 else if( PRIVATE.getValue() == value )
117 {
118 return PRIVATE;
119 }
120 else if( UNDEFINED.getValue() == value )
121 {
122 return UNDEFINED;
123 }
124 else
125 {
126 final String error =
127 "Unrecognized category value [" + value + "]";
128 throw new IllegalArgumentException( error );
129 }
130 }
131
132 /**
133 * Create a category by parsing the supplied name.
134 * @param value the category name
135 * @return the corresponding category
136 * @exception IllegalArgumentException if the value is not recognized
137 */
138 public static Category parse( String value ) throws IllegalArgumentException
139 {
140 if( value.equalsIgnoreCase( "system" ) )
141 {
142 return SYSTEM;
143 }
144 else if( value.equalsIgnoreCase( "public" ) )
145 {
146 return PUBLIC;
147 }
148 else if( value.equalsIgnoreCase( "protected" ) )
149 {
150 return PROTECTED;
151 }
152 else if( value.equalsIgnoreCase( "private" ) )
153 {
154 return PRIVATE;
155 }
156 else if( value.equalsIgnoreCase( "undefined" ) )
157 {
158 return UNDEFINED;
159 }
160 else
161 {
162 final String error =
163 "Unrecognized category argument [" + value + "]";
164 throw new IllegalArgumentException( error );
165 }
166 }
167 }
168